//
//  FunnyInTableViewCell.m
//  Zaker
//
//  Created by dllo on 16/3/15.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "FunnyInTableViewCell.h"

@interface FunnyInTableViewCell ()

@property (nonatomic, retain) UIImageView *ima;
@property (nonatomic, retain) UIView *blackView;
@property (nonatomic, retain) UILabel *title;
@property (nonatomic, retain) UILabel *subTitle;

@end

@implementation FunnyInTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.clipsToBounds = YES;
         _ima.contentMode = UIViewContentModeScaleAspectFill;
        
        self.ima = [[UIImageView alloc] init];
        [self.contentView addSubview:_ima];
        
        self.blackView = [[UIView alloc] init];
        [self.contentView addSubview:_blackView];
        _blackView.backgroundColor = [UIColor blackColor];
        _blackView.alpha = 0.2;
        
        self.title = [[UILabel alloc] init];
        [self.contentView addSubview:_title];
        _title.textColor = [UIColor whiteColor];
        _title.font = [UIFont systemFontOfSize:20];
        _title.textAlignment = 1;
        
        self.subTitle = [[UILabel alloc] init];
        [self.contentView addSubview:_subTitle];
        _subTitle.textColor = [UIColor whiteColor];
        _subTitle.font = [UIFont systemFontOfSize:14];
        _subTitle.textAlignment = 1;
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _ima.frame = CGRectMake(1, 1, SCREEN_WIDTH - 2, self.contentView.frame.size.height - 2);
    _blackView.frame = self.contentView.frame;
    _title.frame = CGRectMake(0, 0, SCREEN_WIDTH, 25);
    _title.center = CGPointMake(_title.center.x, self.contentView.center.y - 20);
    _subTitle.frame = CGRectMake(0, _title.frame.origin.y + _title.frame.size.height, SCREEN_WIDTH, 20);
}

- (void)setModel:(FunnyInModel *)model
{
    if (_model != model) {
        _model = model;
    }
    [_ima sd_setImageWithURL:[NSURL URLWithString:model.url] placeholderImage:[UIImage imageNamed:@"User_Profiles_bg"]];
    _title.text = model.title;
    _subTitle.text = model.content;
}

//- (CGFloat)cellOffset {
//    CGRect centerToWindow = [self convertRect:self.bounds toView:self.window];
//    CGFloat centerY = CGRectGetMidY(centerToWindow);
//    CGPoint windowCenter = self.superview.center;
//    
//    CGFloat cellOffsetY = centerY - windowCenter.y;
//    
//    CGFloat offsetDig =  cellOffsetY / self.superview.frame.size.height * 2;
//    CGFloat offset =  -offsetDig * (667/1.7 - 250) / 2;
//    
////    if (- 50.0 <= offset <= 50.0) {
////        CGAffineTransform transY = CGAffineTransformMakeTranslation(0,offset);
////        self.ima.transform = transY;
////        NSLog(@"______%f", offset);
////        return offset;
////    }
////    return 0;
//    CGAffineTransform transY = CGAffineTransformMakeTranslation(0,offset);
//    self.ima.transform = transY;
//    NSLog(@"______%f", offset);
//    return offset;
//}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
